{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Parameter Counting Examples\n",
    "\n",
    "This notebook demonstrates how to count and print the trainable parameters of CLIP vision models using fusion bench. \n",
    "The notebook contains examples for two different model variants:\n",
    "\n",
    "- openai/clip-vit-base-patch32\n",
    "- openai/clip-vit-large-patch14\n",
    "\n",
    "For each model, the following information is printed:\n",
    "\n",
    "- Total number of parameters.\n",
    "- Number of trainable parameters.\n",
    "- Percentage of parameters that are trainable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "from fusion_bench.utils import count_parameters, print_parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "trainable params: 87.46M || all params: 87.46M || trainable%: 100.0000\n",
      "87456000 87456000\n"
     ]
    }
   ],
   "source": [
    "from transformers import CLIPVisionModel\n",
    "\n",
    "model = CLIPVisionModel.from_pretrained(\"openai/clip-vit-base-patch32\")\n",
    "print_parameters(model)\n",
    "trainable_params, all_params = count_parameters(model)\n",
    "print(trainable_params, all_params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "trainable params: 303.18M || all params: 303.18M || trainable%: 100.0000\n",
      "303179776 303179776\n"
     ]
    }
   ],
   "source": [
    "model = CLIPVisionModel.from_pretrained(\"openai/clip-vit-large-patch14\")\n",
    "print_parameters(model)\n",
    "trainable_params, all_params = count_parameters(model)\n",
    "print(trainable_params, all_params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fusionbench",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
